# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def sumNumbers(self, root: TreeNode, parentSum=0) -> int:
        if root is None:
            return 0
        if root.left is None and root.right is None:
            return parentSum * 10 + root.val
        return self.sumNumbers(root.left, parentSum * 10 + root.val) + self.sumNumbers(root.right, parentSum * 10 + root.val)


if __name__ == '__main__':
    so = Solution()
    root = TreeNode(1)
    root.left = TreeNode(0)
    r = so.sumNumbers(root)
    print(r)
